package com.ssm.service.impl;

import com.ssm.mapper.ProductMapper;
import com.ssm.po.Product;
import com.ssm.po.ProductExample;
import com.ssm.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;

    @Override
    public List<Product> findAll() {
        return productMapper.selectByExample(new ProductExample());// 不传任何条件去查询
    }

    @Override
    @Transactional
    public void updateProduct(Product product) {
        productMapper.updateByPrimaryKey(product);
        // int a = 1 / 0;
    }

    @Override
    @Transactional
    public void deleteByPid(Integer pid) {
        productMapper.deleteByPrimaryKey(pid);
    }

    @Override
    @Transactional
    public void saveProduct(Product product) {
        productMapper.insert(product);
    }

    @Override
    public Product findByPid(Integer pid) {
        return productMapper.selectByPrimaryKey(pid);
    }
}
